package com.fgqm.android.ui

import android.text.TextUtils
import com.fgqm.android.R
import com.wxl.common.base.AbsActivity
import com.wxl.common.util.ImgLoader
import com.wxl.common.util.KeyBoardUtil
import com.wxl.common.util.Toll
import com.wxl.common.util.ValidationUtils
import kotlinx.android.synthetic.main.activity_login_layout.*

class LoginActivity : AbsActivity() {

    override fun getCreateContentViewId(): Int {
        return R.layout.activity_login_layout
    }

    override fun onCreateViewChanged() {
        ImgLoader.loadResouce(loginBackgroundImg,R.mipmap.icon_login_background)
        loginBtn.setOnClickListener {
            submitLogin()
        }
        loginWeChatLayout.setOnClickListener {  }
        loginDealText.setOnClickListener {  }
    }


    /**
     * 提交登录表单
     */
    private fun submitLogin(){
        if(TextUtils.isEmpty(loginMobileEt.text)){
            Toll.toll("请输入手机号")
            return
        }
        if(!ValidationUtils.isMobile(loginMobileEt.text.toString())){
            Toll.toll("请输入正确的手机号")
            return
        }
        if(TextUtils.isEmpty(loginPwdEt.text)){
            Toll.toll("请输入密码")
            return
        }
        hideKeyboard()
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        hideKeyboard()
    }

    private fun hideKeyboard(){
        KeyBoardUtil.hideSoftInput(loginMobileEt)
        KeyBoardUtil.hideSoftInput(loginPwdEt)
    }
}